package com.inossem.warehousestorage_inossem.request.storage;

import android.app.Dialog;
import android.content.Context;
import android.text.TextUtils;

import com.android.volley.toolbox.JsonObjectRequest;
import com.google.gson.Gson;
import com.inossem.utils.log.LogUtils;
import com.inossem.warehousestorage_inossem.bean.storage.StorageManageMatrBean;
import com.inossem.warehousestorage_inossem.bean.storage.StorageManageMatrCommitBean;
import com.inossem.warehousestorage_inossem.bean.storage.StorageManageRespBean;
import com.inossem.warehousestorage_inossem.bean.storage.StorageManageValidBean;
import com.inossem.warehousestorage_inossem.constant.RequestConstant;
import com.inossem.warehousestorage_inossem.dialog.DialogUtils;
import com.inossem.warehousestorage_inossem.listener.GsonBeanListener;
import com.inossem.warehousestorage_inossem.listener.StringRequestListener;
import com.inossem.warehousestorage_inossem.manage.RequestManage;
import com.inossem.warehousestorage_inossem.model.StringResponse;
import com.inossem.warehousestorage_inossem.request.Request;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by leij on 2017/6/12.
 */

public class StorageManageMatrRequest extends Request {
    private static final String CONDITION = "condition";//查询条件
    public static String request(Context context, String no, GsonBeanListener gsonBeanListener) {
        String tag;
        Map<String, String> params = new HashMap<>();
        if(!TextUtils.isEmpty(no)){
            params.put(CONDITION, no);
        }
        String url = RequestManage.getUrl(context,RequestConstant.URL_STORAGE_MANAGE_MATR_LIST+ RequestManage.mapEncodeToParams(params));
        tag =  RequestManage.getHttpsGetWithLoading(context, url, new StringRequestListener() {
            @Override
            public void onSuccess(StringResponse stringRequestResponse) {
                Gson gson = new Gson();
                String json = stringRequestResponse.getResponseInfo();
                StorageManageMatrBean bean = gson.fromJson(json, StorageManageMatrBean.class);
                excuteJsonBean(context, bean, bean.getCode(), bean.getMsg(), gsonBeanListener);
            }
        });
        return tag;
    }
    public static String valid  (Context context, StorageManageValidBean.DataBean bean, GsonBeanListener gsonBeanListener) {
        String tag;
        Gson gson = new Gson();
        String url = RequestManage.getUrl(context,RequestConstant.URL_STORAGE_MANAGE_MATR_VALID);
        String body = gson.toJson(bean);
        tag  = RequestManage.getHttpsPostWithLoading(context, url,body, new StringRequestListener() {
            @Override
            public void onSuccess(StringResponse stringRequestResponse) {

                String json = stringRequestResponse.getResponseInfo();
                StorageManageRespBean bean = gson.fromJson(json, StorageManageRespBean.class);
                excuteJsonBean(context, bean, bean.getCode(), bean.getMsg(), gsonBeanListener);
            }
        });
        return tag;
    }
    public static String commit(Context context, StorageManageMatrCommitBean.DataBean bean, GsonBeanListener gsonBeanListener) {
        String tag;
        Gson gson = new Gson();
        String url = RequestManage.getUrl(context,RequestConstant.URL_STORAGE_MANAGE_MATR_SUBMIT);
        String body = gson.toJson(bean);
        tag = RequestManage.getHttpsPostWithLoading(context, url,body, new StringRequestListener() {
            @Override
            public void onSuccess(StringResponse stringRequestResponse) {

                String json = stringRequestResponse.getResponseInfo();
                StorageManageRespBean bean = gson.fromJson(json, StorageManageRespBean.class);
                excuteJsonBean(context, bean, bean.getCode(), bean.getMsg(), gsonBeanListener);
            }
        });
        return tag;
    }

}
